import java.util.TreeSet;

public class TreeSetExample {
    public static void main(String[] args) {
        // 创建一个 TreeSet
        TreeSet<Integer> treeSet = new TreeSet<>();

        // 添加元素
        treeSet.add(10);
        treeSet.add(5);
        treeSet.add(20);
        treeSet.add(15);

        // 打印 TreeSet
        System.out.println("TreeSet: " + treeSet);

        // 检查元素是否存在
        boolean containsFive = treeSet.contains(5);
        System.out.println("Contains 5: " + containsFive);

        // 获取第一个和最后一个元素
        int first = treeSet.first();
        int last = treeSet.last();
        System.out.println("First element: " + first);
        System.out.println("Last element: " + last);

        // 删除元素
        treeSet.remove(10);
        System.out.println("TreeSet after removing 10: " + treeSet);

        // 遍历 TreeSet
        System.out.print("Elements in TreeSet: ");
        for (int element : treeSet) {
            System.out.print(element + " ");
        }
    }
}